Application of Control Charts in Pairs Trading: An Analysis of BIST30 Stock Indices

Project code, data results and data figures are below; discussion and conclusion are after these.

We get all data from excels and create a column for each stock.

Calculation of correlation for first 3600 inputs, that is 1.5 year between 2018-January and 2019-July, and two of the most correlated stock pairs founded. These are GARAN-AKBNK and SAHOL-VKBNK.

This linreg function provide train data and call test_linear function to test linear regression.

With symbols, we prepare data for buy and sell orders correctly by using two functions below. Our strategy is buying a stock if a residual is above UCL and selling if a residual is below LCL.

We call functions for GARAN-AKBNK and test the trading strategy for the interval between 2019-July and 2020-July.

Linear Regression Model for GARAN-AKBNK with using first 3600 input as train data.

We use 1-sigma for limits and the graph is resulted like that with limits for train data. It is applied in linreg function.

These are our orders and profits, GARAN creates 20% profit in 1 year and AKBKN creates a 1% loss in 1 year.

These graph is belong to test data, between 2019-July and 2020-July, and UCL and LCL are seen here.

Linear Regression Model for SAHOL-VAKBN with using first 3600 input as train data.

Linear Regression Model for SAHOL-VAKBN with using first 3600 input as train data.

We use 1-sigma for limits and the graph is resulted like that with limits for train data. It is applied in linreg function.

These are our orders and profits, SAHOL creates 60% profit in 1 year and VAKBN creates a 10% loss in 1 year.

These graph is belong to test data, between 2019-July and 2020-July, and UCL and LCL are seen here.

Moving Average Time Series Model for GARAN-AKBNK

GARAN/AKBNK parity is used for detection of mean and std for each 30 period. LCL is determined as mean minus 3std and UCL is determined as mean plus 3std. If data is below LCL, we buy GARAN and sell AKBNK; if data is above UCL, we buy AKBNK and sell GARAN.

GARAN creates 100% profit and AKBNK creates 40% loss in the same period as linear regression model.

SAHOL creates 65% profit and AKBNK creates 64% loss in the same period as linear regression model.

DISCUSSION

In linear regression model, data between 2018 January and 2020 July is used. Data is divided as train data, from 2018 January to 2019 July, and test data, from 2019 July to 2020 July. Furthermore, the most correlated stocks are found for 2018 January/2019 July. Therefore, the model is not so successful in trading. In other words, it is assumed that we does not know anything about after 2019 July while creating trade simulation.

Simple trade simulation based on residuals between data predicted by linear regression model and real data. If residuals above UCL, we create a buy order for a stock and a sell order for another stock because they should be correlated for the model. We change orders residuals below LCL and try to catch cycles between stocks. However, the model does not catch that the correlation of stocks may decrease permanently; therefore, we may update model after every data comes true.

In moving average model, data between 2019 July and 2020 July is used because there is no need for train data. Also, stock1/stock2 parity is created. Mean and limits are updated for each data because time series should be adaptive for each new data. 30 is used for window and limits are created for 'mean+-std*3'. If the parity is above UCL or is below LCL, a buy order for a stock and a sell order for another stock are created until another out-of-limits situation.

CONCLUSION

Both methods do not create a great profit compared to normal cumulative return stocks for related dates. In stocks market, there are so external effects like political, sectoral and company related developments. Therefore, just looking correlation and relation between two data is wrong. However, our models can be better with different ordering buy-sell strategies and different control limit approaches like EWMA charts and so on.